package cn.tedu.io;

import sun.security.krb5.SCDynamicStoreConfig;

import java.io.*;
import java.util.Scanner;

//测试 文件复制
public class Test5_Copy {
    public static void main(String[] args) throws IOException {
        System.out.println("请您输入源文件路径");
        String frompath = new Scanner(System.in).nextLine();
        File from = new File(frompath);

        System.out.println("请您输入目标文件路径");
        String topath = new Scanner(System.in).nextLine();
        File to = new File(topath);

        copyOf(from, to);//调用方法完成复制
        System.out.println("恭喜您，文件复制完成！");
    }
    public static void copyOf(File from, File to) throws IOException {
        InputStream in = new BufferedInputStream(new FileInputStream(from));
        OutputStream out = new BufferedOutputStream(new FileOutputStream(to));

        int b = 0;
        byte[] bs = new byte[8192];
        while ((b = in.read(bs)) != -1){
            out.write(bs);
        }

        in.close();
        out.close();
    }
}
